using System;
using System.Collections.Generic;
using System.Text;

namespace ColladaDotNet.OpenTKMapping
{
	public class NodeCollection : CollectionWithIds<Node>
    {
    	VisualScene scene;
		Node parent;

		//private readonly List<Node> childNodes = new List<Node>();

    	public NodeCollection(VisualScene scene)
    	{
    		this.scene = scene;
    	}

		public NodeCollection(Node node)
		{
			this.parent = node;
			if (parent != null)
				scene = parent.Scene;
		}

		public List<Node> ChildNodes
		{
			get
			{
				return itemList;
			}
		}

		public override void Add(Node node)
        {
            ChildNodes.Add(node);
    		node.Parent = parent;
			node.Scene = scene??parent.Scene;
		}

		//public void RemoveChild(Node node)
		//{
		//    childNodes.Remove(node);
		//    node.Parent = null;
		//    node.VisualScene = null;
		//}

        public Node this[int index]
        {
            get
            {
                return ChildNodes[index];
            }
        }

		protected override string GetIdOf(Node item)
		{
			return item.Id;
		}

		public void Create(IEnumerable<node> nodes)
    	{
    		foreach (var node in nodes)
    		{
    			Add(scene.Document.CreateElement<Node>(node));
			}
    	}

    	public void Render()
    	{
    		foreach (var node1 in ChildNodes)
    		{
    			node1.Render();
    		}
    	}
    }
}
